const express = require('express')   // 引入
let app = express()   // 使用
app.listen(8081, ()=>{console.log('端口号:8081; 监听成功...')})

app.use((req,res,next) => {
  // 这里可以直接拿origin：req.headers.origin
  // 也可以直接判断origin是否在白名单，才进行往下面走
  res.header('Access-Control-Allow-Origin', 'http://localhost:8520');
  res.header('Access-Control-Allow-Headers', 'Content-Type,Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild');
  res.header('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE,OPTIONS');
  next()
})
app.use((req,res,next) => {
  // 这里可以直接拿origin：req.headers.origin
  // 也可以直接判断origin是否在白名单，才进行往下面走
  res.header('Access-Control-Allow-Origin', 'http://127.0.0.1:5173');
  res.header('Access-Control-Allow-Headers', 'Content-Type,Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild');
  res.header('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE,OPTIONS');
  next()
})
// app.use((req, res, next) => {
//   console.log('req.headers.origin', req.headers.origin);
//   const allowedOrigin = "http://localhost:8521"
//   if (req.headers.origin === allowedOrigin) {
//     res.header("Access-Control-Allow-Origin", allowedOrigin);
//     res.header(
//       "Access-Control-Allow-Headers",
//       "Content-Type, Content-Length, Authorization, Accept, X-Requested-With, yourHeaderFeild"
//     );
//     res.header("Access-Control-Allow-Methods", "PUT, POST, GET, DELETE, OPTIONS");
//   }
//   next();
// })

// app.get('/',(req,res)=>{res.send('<h1>hello, wing</h1>')})
// const routes = require('./src/get/box')
app.use('/get/', require('./src/get/box'))
app.use('/get/', require('./src/get/link'))
app.use('/get/', require('./src/get/box_link'))

